<?php
namespace PackageSpy;
use Nette;
class RoleModel extends Nette\Object
{
	protected $connection;

	public function __construct(Nette\Database\Connection $db)
	{
		$this->connection = $db;
	}

	protected function getTable()
	{
		return $this->connection->table('role');
	}
	
	/*
	 *vrátí seznam balíků (refpackage) přihlášeného uživatele pro zadanou roli 
	 */
	public function searchRoleByRole($roletype)
	{
		$result = array();
		$rows = $this->getTable()->where('email', \Nette\Environment::getUser()->getIdentity()->getId())->where('refroletype', $roletype);
		$i = 0;
		foreach ($rows as $row){
			$i++;
			//print_r($row->);
			array_push($result, new RoleDomain($row));
		}
		return $result;
	}
	
	//uloží roli TODO
	public function saveRole($refPackage, $roletype)
	{
		$row = $this->getTable()->insert(array(
				'refroletype' => $roletype,
				'refpackage'  => $refPackage,
				'email'		  => \Nette\Environment::getUser()->getIdentity()->getId()
		));
	}
}